package com.five.taotao.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.five.taotao.R;
import com.five.taotao.entity.Product;
import com.five.taotao.entity.ShoppingCart;

import java.util.List;

/**
 * Created by asus on 2016/11/10.
 */
public class ProductOrderAdapter extends BaseAdapter {

    private List<ShoppingCart.ListBean> mData;
    private Context context;
    private ShoppingCart.ListBean product;

    public ProductOrderAdapter(List<ShoppingCart.ListBean> mData, Context context) {
        this.mData = mData;
        this.context = context;
    }

    @Override
    public int getCount() {
        return this.mData.size();
    }

    @Override
    public Object getItem(int i) {
        return this.mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(this.context).inflate(R.layout.order_list_item, null, false);
            viewHolder = new ViewHolder();
            viewHolder.pic = (ImageView) view.findViewById(R.id.pic);
            viewHolder.pname = (TextView) view.findViewById(R.id.pname);
            viewHolder.desc = (TextView) view.findViewById(R.id.desc);
            viewHolder.price = (TextView) view.findViewById(R.id.price);
            viewHolder.num = (TextView) view.findViewById(R.id.suliang);
            viewHolder.all_price = (TextView) view.findViewById(R.id.all_price);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        product = this.mData.get(i);


        Glide.with(context)
                .load(product.getUrl())
                .into(viewHolder.pic);
        viewHolder.pname.setText(product.getName());
        viewHolder.price.setText("￥:" + product.getVipprice());
        viewHolder.num.setText(product.getNum() + "件");
        viewHolder.desc.setText(product.getIntroduce());
        viewHolder.all_price.setText("￥" + product.getVipprice() * product.getNum());
//        money_pay.setText("￥" + (double) (product.getPrice() * num));
        return view;
    }

    class ViewHolder {
        ImageView pic;
        TextView pname;
        TextView desc;
        TextView price;
        TextView num;
        TextView all_price;
    }
}
